package br.com.wssa.smmb.dao.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import br.com.wssa.smmb.dao.RoleDAO;
import br.com.wssa.smmb.entidades.Role;

/**
 * Classe GrupoUsuarioDAOImpl.
 * 
 * @author ssilva
 */
@Repository("roleDAO")
public class RoleDAOImpl extends GenericDAOImpl<Role> implements RoleDAO {

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	protected Class<?> getClazz() {
		return Role.class;
	}

	public Role obterRole(String role) {
		Query query = sessionFactory.getCurrentSession().createQuery("from Role r where r.role = ?");
		query.setEntity(0, role);
		List<?> roles = query.list();
		if (CollectionUtils.isNotEmpty(roles)) {
			return (Role) roles.get(0);
		}
		return null;
	}

}
